#include <iostream>
#include <string>
#define LL long long
using namespace std;

const int kMaxN = 310;
const int kInf = 1e9;

int a[kMaxN];
pair<int, LL> dis[kMaxN][kMaxN];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) {
      if (s[j] == 'Y') {
        dis[i][j] = make_pair(1, -a[i] - a[j]);
      } else {
        dis[i][j] = make_pair(kInf, -a[i] - a[j]);
      }
    }
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        pair<int, LL> tmp(dis[i][k].first + dis[k][j].first, dis[i][k].second + dis[k][j].second + a[k]);

        if (tmp < dis[i][j]) {
          dis[i][j] = tmp;
        }
      }
    }
  }

  int q;

  for (cin >> q; q; q--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (dis[u][v].first == kInf) {
      cout << "Impossible\n";
    } else {
      cout << dis[u][v].first << " " << -dis[u][v].second << "\n";
    }
  }
  return 0;
}